#------------------------------------------------------------------------------
# osxGlobals.pl
#   Plugin for MacRipper
#   Get OS global settings (locale and timezone)
#
# Change history
#   20120605 [fpi] * released
#
# References
#
# copyright 2012 Francesco Picasso <francesco.picasso@gmail.com>
#------------------------------------------------------------------------------

package osxGlobals;
use strict;

#------------------------------------------------------------------------------

my %config = (
    version         => 20120605,
    hasDescr        => 1,
    hasRefs         => 0,
	applyto			=> 'osx',
	srctype			=> "plist",
   	srcfile		    => ".GlobalPreferences.plist",
   	srcpath		    => "/Library/Preferences/"
);

sub getConfig       { return %config; }
sub getDescription  { return "Get OS global settings (locale and timezone)"; }
sub getReferences   {}
sub getSourcePath   { return $config{srcpath}; }
sub getSourceFile   { return $config{srcfile}; }
sub getSourceType   { return $config{srctype}; }
sub getVersion      { return $config{version}; }
sub getApplyTo      { return $config{applyto}; }

#------------------------------------------------------------------------------
# helpers

my $VERSION = getVersion();
my $tab;
my $tab0 = '';
my $tab1 = '  ';
my $tab2 = $tab1.$tab1;
my $tab3 = $tab1.$tab1.$tab1;
my $noalign = "%s";
my $align23 = "%-23s";
my $align25 = "%-25s";

#------------------------------------------------------------------------------

sub pluginmain {
	my $class = shift;
	my $plist = shift;
    my $tzone = shift;
	::logMsg("Launching osxGlobals v.".$VERSION);
    die "Invalid PLIST object" if ( not defined $plist );

    my $name;
    my $subk;
    my $data;
    my $align = $align25;
    
    $name = 'AppleLocale';
    $data = ::getPlistKeyValue( $plist, $name );
    $data = 'Not found' if not defined $data;
    ::rptMsg(sprintf($tab."$align = %s", $name, $data));

    $name = 'Country';
    $data = ::getPlistKeyValue( $plist, $name );
    $data = 'Not found' if not defined $data;
    ::rptMsg(sprintf($tab."$align = %s", $name, $data));
    
    $name = 'com.apple.preferences.timezone.selected_city';
    $subk = ::getPlistKeyValue( $plist, $name );
    ::rptMsg("");
    if ( defined $subk )
    {
        ::rptMsg("$name");
        $tab = $tab1;
        $align = $align23;
        $name = 'CountryCode';
        $data = ::getPlistKeyValue( $subk, $name );
        $data = 'Not found' if not defined $data;
        ::rptMsg(sprintf($tab."$align = %s", $name, $data));
        
        $name = 'GeonameID';
        $data = ::getPlistKeyValue( $subk, $name );
        $data = 'Not found' if not defined $data;
        ::rptMsg(sprintf($tab."$align = %s", $name, $data));

        $name = 'Latitude';
        $data = ::getPlistKeyValue( $subk, $name );
        $data = 'Not found' if not defined $data;
        ::rptMsg(sprintf($tab."$align = %s", $name, $data));

        $name = 'Longitude';
        $data = ::getPlistKeyValue( $subk, $name );
        $data = 'Not found' if not defined $data;
        ::rptMsg(sprintf($tab."$align = %s", $name, $data));

        $name = 'Name';
        $data = ::getPlistKeyValue( $subk, $name );
        $data = 'Not found' if not defined $data;
        ::rptMsg(sprintf($tab."$align = %s", $name, $data));
        
        $name = 'TimeZoneName';
        $data = ::getPlistKeyValue( $subk, $name );
        $data = 'Not found' if not defined $data;
        ::rptMsg(sprintf($tab."$align = %s", $name, $data));
        
        $name = 'Version';
        $data = ::getPlistKeyValue( $subk, $name );
        $data = 'Not found' if not defined $data;
        ::rptMsg(sprintf($tab."$align = %s", $name, $data));
        
    }
    else {
        ::rptMsg("'$name' not found");
        $name = 'com.apple.TimeZonePref.Last_Selected_City';
        $subk = ::getPlistKeyValue( $plist, $name );
        $tab = $tab1;
        ::rptMsg("");
        if ( defined $subk ) {
            ::rptMsg("$name");
            ::rptMsg($tab.$_) for (@{$subk});
        }
        else { ::rptMsg("'$name' not found"); }
    }
    ::rptMsg("");
}

#------------------------------------------------------------------------------
1;